/**
 * Created with JetBrains WebStorm.
 * User: YinHeeJoo
 * Date: 14-11-7
 * Time: 下午3:06
   table operations
 */

var css_constants = {
    'PROPTERTY_BGC' : "background-color"
}

var css_colors = {

}

function table_grid(_id, _headerColor, _footerColor, _oddColor, _evenColor, _moveonColor){
    this.id=_id;
    this.headerColor = _headerColor;
    this.footerColor = _footerColor;
    this.mouseonColor = _moveonColor;
    this.oddColor = _oddColor;
    this.evenColor = _evenColor;
    this.init = function(){
        $(this.id + ' tr:even').css(css_constants.PROPTERTY_BGC, this.evenColor);
        $(this.id + ' tr:odd').css(css_constants.PROPTERTY_BGC, this.oddColor);
        $(this.id + ' tr:first').css(css_constants.PROPTERTY_BGC, this.headerColor);
        $(this.id + ' tr:last').css(css_constants.PROPTERTY_BGC, this.footerColor);
    }

    this.setMouseOverColor = function(){
        var $trs = $(this.id + ' tr');
        var len = $trs.size();

        for(var i=1; i<len-1; ++i) {
            bindMouseoverEvent($trs.get(i), this.mouseonColor);
            bindMouseleaveEvent($trs.get(i), this.evenColor, this.oddColor, i);
        }

    }
    this.renderGridColor = function() {
        init();
        $(this.id + ' tr:first').css(css_constants.PROPTERTY_BGC, this.headerColor);
        $(this.id + ' tr:last').css(css_constants.PROPTERTY_BGC, this.footerColor);
    }

}

function bindMouseoverEvent(o, color){
    $(o).mouseover(function(){
        $(o).css(css_constants.PROPTERTY_BGC, color);

    })
}

function bindMouseleaveEvent(o, evenColor, oddColor, index) {
    $(o).mouseout(function(){
        if(index % 2 == 0)
            $(o).css(css_constants.PROPTERTY_BGC, evenColor);
        else
            $(o).css(css_constants.PROPTERTY_BGC, oddColor);
    })
}